<?php
/**
 * Created by PhpStorm.
 * User: cen
 * Date: 2020/6/8
 * Time: 22:05
 */

namespace app\index\controller;

use app\index\BaseController;
use think\Controller;
use app\admin\model\NewsModel;

class News extends BaseController
{
    public function index(){
        $zx =  NewsModel::order('create_time', 'desc')->limit(5)->select();
        $gg =  NewsModel::where('type','公告')->order('create_time', 'desc')->limit(5)->select();
        $gl =  NewsModel::where('type','攻略')->order('create_time', 'desc')->limit(5)->select();

        $hd =  NewsModel::where('type','活动')->order('create_time', 'desc')->limit(5)->select();
        $bl =  NewsModel::where('type','爆料')->order('create_time', 'desc')->limit(5)->select();


        $this->assign('zx',$zx);
        $this->assign('gg',$gg);
        $this->assign('gl',$gl);
        $this->assign('hd',$hd);
        $this->assign('bl',$bl);
        return $this->fetch();
    }

    public function type(){
        $id = $this->request->param('id');

        $type = '';
        switch ($id){
            case 1:
                $res =  NewsModel::order('create_time', 'desc')->paginate(5,true);
                $type = 'zx';
                break;
            case 2:
                $res =  NewsModel::where('type','爆料')->order('create_time', 'desc')->paginate(5,true);
                $type = 'bl';
                break;
            case 3:
                $res =  NewsModel::where('type','公告')->order('create_time', 'desc')->paginate(5,true);
                $type = 'gg';
                break;
            case 4:

                $res =  NewsModel::where('type','活动')->order('create_time', 'desc')->paginate(5,true);
                $type = 'hd';
                break;

            case 5:
                $res =  NewsModel::where('type','攻略')->order('create_time', 'desc')->paginate(5,true);
                $type = 'gl';
                break;
        }

       // $this->assign($type,$type);



        $page = $res->currentPage();
       // $this->assign('page',$page);


        return json(
            [
                'type' =>$id,
                'page' =>$page,
                'list' => $res->toArray()
            ]
        );


    }

}